package cn.lanqiao.book.dao.impl;

import cn.lanqiao.book.dao.IBaseDao;
import cn.lanqiao.book.dao.IUserDao;
import cn.lanqiao.book.pojo.User;

public class UserDaoImpl implements IUserDao {

    private IBaseDao IBaseDao = new IBaseDao();

    //根据用户名查询密码 返回值为 字符串类型的密码
    @Override
    public String queryPassword(String username) {
        String sql = "select u_password from b_user where u_username=?";
        return (String) IBaseDao.queryForSingleValue(sql, username);
    }

    //向数据库中添加一条用户记录 返回值是受影响的行数
    @Override
    public int addUser(User user) {
        String sql = "insert into b_user(u_username,u_password,u_email,u_sex,u_qq,u_pweb) values(?,?,?,?,?,?)";
        return IBaseDao.update(sql, user.getU_username(), user.getU_password(), user.getU_email(), user.getU_sex(), user.getU_qq(), user.getU_pweb());
    }

    @Override
    public String queryEmail(String username) {
        String sql = "select u_email from b_user where u_username=?";
        return (String) IBaseDao.queryForSingleValue(sql, username);
    }

    @Override
    public Boolean updatePassword(String username, String password) {
        String sql = "update b_user set u_password=? where u_username=?";
        if (IBaseDao.update(sql, password, username) == 1) {
            return true;
        } else {
            return false;
        }
    }
}


